﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Text;

namespace OpenLS.Spreadsheet.UI.Internals
{
    class WorkbookProtectionViewModel
    {
        private readonly Workbook _workbook;

        public WorkbookProtectionViewModel(Workbook workbook)
        {
            Contract.Requires(workbook != null);
            _workbook = workbook;
        }

        public bool CanUnprotect
        {
            get
            {
                if (_workbook.Protection == null)
                    return false;
                return _workbook.Protection.IsValidPassword(Password);
            }
        }
        public bool HasProtection { get { return _workbook.Protection != null; } }

        public bool Structure { get; set; }
        public bool Windows { get; set; }
        public void Unprotect()
        {
            _workbook.Protection = null;
            
        }
        public void Protect()
        {
            _workbook.Protection = new WorkbookProtection();
            _workbook.Protection.SetPasswordHash(Password);
            _workbook.Protection.LockStructure = Structure;
            _workbook.Protection.LockWindows = Windows;
        }

        public string Password{ get; set; }
    }
}
